<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class vote extends CI_Controller {
		public function __construct()
		{
			parent::__construct();
			//$this->output->enable_profiler(TRUE);
			$this->load->helper('html');
			$this->load->helper('util');
			$this->load->library('form_validation');
			$this->load->config('config_ip');
			$this->load->library('pagination');
			$this->load->library('ckeditor');
			$this->load->library('ckfinder');
			$this->load->model('front/vote_model', 'vote_model');	
			session_start(); 
		}
		public function index( $offset = 0)
		{
			redirect('cms/vote/lst/');
		}
		public function lst( $offset = 0)
		{
			$sort_by = 'time_update'; $sort_order = 'desc';
			if(isset($_SESSION['userinfo']))
			{       

				$data = array();
				$data['fields'] = array(
					'vote_id' => 'ID',				
					'title' => 'Tiêu đề',
					'body' => 'Nội dung',
					'image' => 'Ảnh',		
					'type' => 'Kiểu',	
					'status' => 'Trạng thái',			
					'note' => 'Ghi chú',
					);
				// Access data
				$limit = 10;
				$result = $this->vote_model->get_list_vote($limit, $offset, $sort_by, $sort_order);
				$data['rows'] = $result['rows'];
				$data['num_rows'] = $result['num_rows'];
				// Paging
				$segment_array=$this->uri->segment_array();
				$segment_count=$this->uri->total_segments();
				$config = array();
				$config['base_url'] = site_url("cms/vote/lst/");
				$config['total_rows'] = $data['num_rows'];
				$config['per_page'] = $limit;
				$config['uri_segment'] = 4;
				$this->pagination->initialize($config);
				$data['offset'] = $offset;
				$data['limit'] = $limit;
				$data['pagination'] = $this->pagination->create_links();
				// Sorting
				$data['sort_by'] = $sort_by;
				$data['sort_order'] = $sort_order;

				// Load view
				$this->load->view('admin/header_view',$data);
				$this->load->view('admin/vote_view');
				$this->load->view('admin/footer_view',$data);
				
			}
			else
			{
				redirect('/cms/', 'refresh');
			}
		}
		
	}
